﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gengens.Disk.Entity
{
    public class BaseModel<Model> : IBaseModel<Model> where Model : class
    {
        public Guid Id { get; set; } = Guid.NewGuid();

        /// <summary>
        /// 创建时间
        /// </summary>
        /// <remarks>
        /// 将在生命周期中维护该字段
        /// </remarks>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        /// <remarks>
        /// 将在生命周期中维护该字段
        /// </remarks>
        public DateTime UpdateTime { get; set; }

        public virtual void OnModelCreate(EntityTypeBuilder<Model> builder)
        { }
        public virtual bool OnDelete()
        {
            //以防假删除，故更新字段
            UpdateTime = DateTime.Now;
            return true;
        }
        public virtual bool OnInsert()
        {
            UpdateTime = DateTime.Now;
            CreateTime = DateTime.Now;
            return true;
        }

        public virtual bool OnSelect() => true;
        public virtual bool OnUpdate()
        {
            UpdateTime = DateTime.Now;
            return true;
        }
    }
}
